using Microsoft.AspNetCore.Mvc;
using JTZY.Model.Business.Dto;
using JTZY.Model.Business;
using JTZY.Service.Business.IBusinessService;
using JTZY.Admin.WebApi.Filters;

//创建时间：2025-01-22
namespace JTZY.Admin.WebApi.Controllers.Business
{
    /// <summary>
    /// 用户余额表
    /// </summary>
    [Verify]
    [Route("business/Corecmsuserbalance")]
    public class CorecmsuserbalanceController : BaseController
    {
        /// <summary>
        /// 用户余额表接口
        /// </summary>
        private readonly ICorecmsuserbalanceService _CorecmsuserbalanceService;

        public CorecmsuserbalanceController(ICorecmsuserbalanceService CorecmsuserbalanceService)
        {
            _CorecmsuserbalanceService = CorecmsuserbalanceService;
        }

        /// <summary>
        /// 查询用户余额表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "corecmsuserbalance:list")]
        public IActionResult QueryCorecmsuserbalance([FromQuery] CorecmsuserbalanceQueryDto parm)
        {
            parm.userId = HttpContext.GetUId();
            var response = _CorecmsuserbalanceService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询用户余额表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "corecmsuserbalance:query")]
        public IActionResult GetCorecmsuserbalance(int Id)
        {
            var response = _CorecmsuserbalanceService.GetInfo(Id);
            
            var info = response.Adapt<CorecmsuserbalanceDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加用户余额表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "corecmsuserbalance:add")]
        [Log(Title = "用户余额表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCorecmsuserbalance([FromBody] CorecmsuserbalanceDto parm)
        {
            var modal = parm.Adapt<Corecmsuserbalance>().ToCreate(HttpContext);

            var response = _CorecmsuserbalanceService.AddCorecmsuserbalance(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新用户余额表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "corecmsuserbalance:edit")]
        [Log(Title = "用户余额表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCorecmsuserbalance([FromBody] CorecmsuserbalanceDto parm)
        {
            var modal = parm.Adapt<Corecmsuserbalance>().ToUpdate(HttpContext);
            var response = _CorecmsuserbalanceService.UpdateCorecmsuserbalance(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除用户余额表
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete/{ids}")]
        [ActionPermissionFilter(Permission = "corecmsuserbalance:delete")]
        [Log(Title = "用户余额表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCorecmsuserbalance([FromRoute]string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CorecmsuserbalanceService.Delete(idArr));
        }
        /// <summary>
        /// 导出余额明细
        /// </summary>
        /// <returns></returns>
        [Log(Title = "余额明细", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
        [HttpGet("export")]
        [ActionPermissionFilter(Permission = "corecmsuserbalance:export")]
        public IActionResult Export([FromQuery] CorecmsuserbalanceQueryDto parm)
        {
            parm.PageNum = 1;
            parm.PageSize = 100000;
            parm.userId = HttpContext.GetUId();
            var list = _CorecmsuserbalanceService.ExportList(parm).Result;
            if (list == null || list.Count <= 0)
            {
                return ToResponse(ResultCode.FAIL, "没有要导出的数据");
            }
            var result = ExportExcelMini(list, "余额明细", "余额明细");
            return ExportExcel(result.Item2, result.Item1);
        }
    }
}